package com.gym.openapi.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gym.openapi.common.ResponseResult;
import com.gym.openapi.common.ResultTable;
import com.gym.openapi.dao.UserTokenMapper;
import com.gym.openapi.entity.UserToken;
import com.gym.openapi.services.Tokenservices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ming
 * 2021/11/26
 * description:
 */
@Service
public class TokenservicesImpl implements Tokenservices {

    @Autowired
    private UserTokenMapper userTokenMapper;


    /**
     *@author:ming
     *@Date: 2021/11/26
     *@description:分页界面
     */
    @Override
    public ResultTable tokenTable(Integer page, Integer limit, String accessToken) {
        PageHelper.startPage(page, limit, accessToken);
        List<UserToken> userTokenList = userTokenMapper.tokenTable(accessToken);
        PageInfo pt = new PageInfo(userTokenList);
        return new ResultTable(0, "", (int) pt.getTotal(), pt.getList());
    }

    @Override
    public ResponseResult del(Integer[] ids) {
        int i =userTokenMapper.delToken(ids);
        if (i>0) {
            return ResponseResult.getSuccess("成功干掉tokey");
        }
        return ResponseResult.getFail("干不掉tokey");
    }

    @Override
    public ResponseResult update(UserToken t) {
        if (t !=null) {
            int i = userTokenMapper.updateByPrimaryKeySelective(t);
            if (i > 0) {
                return ResponseResult.getSuccess("修改tokey成功");
            }
        }
        return ResponseResult.getFail("动不了它");

    }

    @Override
    public ResponseResult add(UserToken t) {
        if (t !=null) {
            int i = userTokenMapper.insertSelective(t);
            if (i > 0) {
                return ResponseResult.getSuccess("修改tokey成功");
            }
        }
        return ResponseResult.getFail("动不了它");
    }
}
